package me.chan.netty.rpc.server.serialize;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public enum SerializeAlgo implements Serializer {

    JDK(0) {

        JdkSerializer serializer = new JdkSerializer();

        @Override
        public <T> byte[] serialize (T t) throws IOException {

            return serializer.serialize(t);
        }

        @Override
        public <T> T deserialize(Class < T > clazz, byte[] bytes) throws IOException {
            return serializer.deserialize(clazz, bytes);
        }
    },

    JSON(1) {

        JSONSerializer serializer = new JSONSerializer();

        @Override
        public <T> byte[] serialize(T t) throws IOException {
            return serializer.serialize(t);
        }

        @Override
        public <T> T deserialize(Class<T> clazz, byte[] bytes) throws IOException {
            return serializer.deserialize(clazz, bytes);
        }

    },

    HESSIAN(2) {
        @Override
        public <T> byte[] serialize(T t) throws IOException {
            return new byte[0];
        }

        @Override
        public <T> T deserialize(Class<T> clazz, byte[] bytes) throws IOException {
            return null;
        }
    };

    SerializeAlgo(int serial) {
        this.serial = serial;
    }

    private int serial;

    public int getSerial() {
        return this.serial;
    }


    public static void main(String[] args) {
        System.out.println(SerializeAlgo.valueOf("JSON") == SerializeAlgo.JSON);
    }
}
